package com.xiaomo.gitee.datamanager.common.result;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "响应数据模型",name = "响应数据模型",title = "响应数据模型")
public class Result<T> {

    @Schema(
            title = "code",
            description = "响应码",
            format = "int32",
            example = "200",
            requiredMode = Schema.RequiredMode.REQUIRED
    )
    private Integer status;

    @Schema(
            title = "msg",
            description = "响应信息",
            accessMode = Schema.AccessMode.READ_ONLY,
            example = "操作结果",
            requiredMode = Schema.RequiredMode.REQUIRED
    )
    private String msg;

    @Schema(
            title = "data",
            description = "响应数据",
            accessMode = Schema.AccessMode.READ_ONLY,
            requiredMode = Schema.RequiredMode.AUTO
    )
    private T data;

    @Schema(
            title = "isSuccess",
            description = "是否成功",
            format = "boolean",
            requiredMode = Schema.RequiredMode.REQUIRED
    )
    private Boolean isSuccess;

    public static <U> Result<U> ok(U obj) {
        return new Result<>(Integer.parseInt(Code.SUCCESS),"操作成功",obj,true);
    }

    public static <U> Result<U> ok() {
        return new Result<>(Integer.parseInt(Code.SUCCESS),"操作成功",null,true);
    }

    public static <U> Result<U> ok(String msg,U obj) {
        return new Result<>(Integer.parseInt(Code.SUCCESS),msg,obj,true);
    }

    public static <U> Result<U> fail(String msg) {
        return new Result<>(Integer.parseInt(Code.CLIENT_FAILED),msg,null,false);

    }
    public static <U> Result<U> fail(int status,String msg) {
        return new Result<>(status,msg,null,false);
    }


}
